package com.ce.util.chart;

import java.util.HashMap;
import java.util.Iterator;

import com.ce.framework.util.StringUtil;

public class ChartValue {

	private String xid;
	private String text;
	private String color;
	private String url;
	private HashMap<String,String> otherAttr = new HashMap<String,String>();

	public ChartValue(String xid, String text) {
		this(xid,text,null);
	}

	public ChartValue(String xid, String text, String color) {
		this(xid,text,color,null);
	}

	public ChartValue(String xid, String text, String color, String url) {
		super();
		this.xid = xid;
		this.text = text;
		this.color = color;
		this.url = url;
	}

	public ChartValue addAttribute(String name,String value){
		otherAttr.put(name, value);
		return this;
	}

	public Element toElement(){
		Element e = new Element("value",text);
		Iterator<String> it = otherAttr.keySet().iterator();
		String key,val;
		while(it.hasNext()){
			key = it.next();val = otherAttr.get(key);
			e.setAttribute(key, val);
		}
		e.setAttribute("xid", xid);
		if(StringUtil.isNotBlank(color))
			e.setAttribute("color", color);
		if(StringUtil.isNotBlank(url))
			e.setAttribute("url", url);
		return e;
	}

	public String toString(){
		return this.toElement().toString();
	}

	public String getXid() {
		return xid;
	}

	public void setXid(String xid) {
		this.xid = xid;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public HashMap<String, String> getOtherAttr() {
		return otherAttr;
	}

	public ChartValue setOtherAttr(HashMap<String, String> otherAttr) {
		this.otherAttr = otherAttr;
		return this;
	}

}
